package org.online.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.online.conmon.Const;
import org.online.entity.User;

@WebServlet("/login.html")
public class LoginPageServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out = resp.getWriter();

		// 获取上下文对象
		ServletContext context = req.getServletContext() ;
		
		// 在上下文对象中，获取map集合
		@SuppressWarnings("unchecked")
		Map<String,User> map = (Map<String,User>)context.getAttribute(Const.ONLINE_USER_MAP) ;
		
		
		out.print("<!DOCTYPE html>");
		out.print("<html>");
		out.print("<head>");
		out.print("<meta charset='UTF-8'>");
		out.print("<title>用户登录</title>");
		out.print("</head>");
		out.print("<body>");
		out.print("<h3>用户登录</h3>");
		
		// 读取在线人数
		out.print("<h5>当前在线人数：" + map.size() + "</h5>");
		out.print("<form action='login.do' method='post'>");
		out.print("帐号：<input type='text' name='username' value='admin888'/><br/>");
		out.print("密码：<input type='password' name='password' value='123456'/><br/>");
		out.print("<input type='submit' value='登录'/>	");
		out.print("</form>");
		out.print("</body>");
		out.print("</html>");
		
		// 关闭对象
		out.flush();
		out.close();
	}

}
